package com.wyl.pmd.rule.performance;

public class ConsecutiveAppendsShouldReuse {

	public static void main(String[] args) {

		String foo = " ";

		// bad
		StringBuffer buf = new StringBuffer();
		buf.append("Hello");
		buf.append(foo);
		buf.append("World");

		// good
		StringBuffer buf1 = new StringBuffer();
		buf1.append("Hello").append(foo).append("World");
		
		
		StringBuilder buf2 = new StringBuilder();
		buf2.append("Hello").append(" ").append("World");    // poor
		buf2.append("Hello World");                          // good

		buf2.append('h').append('e').append('l').append('l').append('o'); // poor
		buf2.append("hello");                                             // good

		buf2.append(1).append('m');  // poor
		buf2.append("1m");           // good

	}

}
